package com.cs4261.smartalarm.frontend;

import com.cs4261.smartalarm.R;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ToggleButton;
import android.support.v4.app.NavUtils;

public class CreateAlarmActivity extends Activity {

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_alarm);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // Show the Up button in the action bar.
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_create_alarm, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void weatherToggle(View view) {
		 boolean on = ((ToggleButton)view).isChecked();
		 View weather_layout = ((View) view.getParent().getParent()).findViewById(R.id.weather_layout);
		 
		 if(on) {
			 weather_layout.setVisibility(View.VISIBLE);
		 }
		 else {
			 weather_layout.setVisibility(View.GONE);
		 }
	}
	
	public void trafficToggle(View view) {
		 boolean on = ((ToggleButton)view).isChecked();
		 View traffic_layout = ((View) view.getParent().getParent()).findViewById(R.id.traffic_layout);
		 
		 if(on) {
			 traffic_layout.setVisibility(View.VISIBLE);
		 }
		 else {
			 traffic_layout.setVisibility(View.GONE);
		 }
	}
	
	public void cancelCreate(View view) {
		NavUtils.navigateUpFromSameTask(this);
	}
	
	public void createAlarm(View view){
		//Handle adding
		//Refresh main page
		
		NavUtils.navigateUpFromSameTask(this);
	}

}
